<template>
  <div>
    <div class="msg-wrapper">
      <div class="menu-wrapper">
        <ul class="msg-menu">
          <li>
            <div class="menu-title">信息中心</div>
          </li>
          <ul style="padding: 0">
            <li class="menu-item" @click="getDemand(0)">我的需求</li>
            <li class="menu-item" @click="getSupport(1)">收到的赞</li>
            <li class="menu-item" @click="getNotice(2)">系统通知</li>
          </ul>
        </ul>
      </div>
      <div class="msg-content">
        <div class="msg-items">
          <div class="msg-item" v-for="item in itemList" :key="item.id">
            <div class="msg-item-img">
              <img :src="imgUrl(item.portrait)" alt="" />
            </div>
            <div class="msg-item-content">
              <div class="msg-content-text">
                {{ item.bidUserName }}
                <span class="msg">领取了我的需求</span>
                {{ item.request }}
              </div>
              <div class="msg-date">{{ item.bidDate }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "message",
  data() {
    return {
      mySupport: [],
      myDemand: [],
      itemList: [],
    };
  },
  // 先获取我的需求的相关内容展示
  mounted(){
    this.getDemand(0)
  },
  methods: {
    // 获取点赞者或者投标者的用户头像
    imgUrl(url) {
      if (url == "0") {
        return require("../assets/images/user.png");
      } else {
        return "http://120.77.241.190:9999/" + url;
      }
    },
    getSupport(x) {
      // 改变选中内容的样式
      let menuItem = document.getElementsByClassName("menu-item");
      for (let i = 0; i < menuItem.length; i++) {
        if (i == x) {
          menuItem[x].classList.add("item-active");
        } else {
          menuItem[i].classList.remove("item-active");
        }
      }
      axios({
        url: "/api/user/listLikeById?userId" + this.$route.params.userData.id,
        method: "GET",
      }).then((response) => {
        this.itemList = response.data.data;
      });
    },
    getDemand(x) {
      let menuItem = document.getElementsByClassName("menu-item");
      for (let i = 0; i < menuItem.length; i++) {  
        if (i == x) {
          menuItem[i].classList.toggle("item-active");
        } else {
          menuItem[i].classList.remove("item-active");
        }
      }
      axios({
        url: "/api/user/listBidById?userId=" + this.$route.params.userData.id,
        method: "GET",
      }).then((response) => {
        this.itemList = response.data.data;
      });
    },
    getNotice(x) {
      let menuItem = document.getElementsByClassName("menu-item");
      for (let i = 0; i < menuItem.length; i++) {
        if (i == x) {
          menuItem[x].classList.add("item-active");
        } else {
          menuItem[i].classList.remove("item-active");
        }
      }
    },
  },
};
</script>
<style>
.msg-wrapper {
  display: flex;
  background: #f9f9f9;
  padding: 0 250px;
  min-height: 800px;
}
.msg-menu {
  display: block;
  margin: 0;
  padding: 0;
  outline: none;
  list-style: none;
  color: #515a6e;
  font-size: 14px;
  position: relative;
  z-index: 900;
  width: 240px;
  background: #fff;
  border-right: 2px #99999930 solid;
}
.menu-title {
  text-align: center;
  height: 48px;
  line-height: 48px;
  font-size: 14px;
  padding-left: 28px;
  color: #999;
}
.menu-item {
  text-align: center;
  display: block;
  outline: none;
  list-style: none;
  font-size: 14px;
  padding: 14px 24px;
  position: relative;
  cursor: pointer;
  z-index: 1;
  color: #999;
}
.item-active {
  color: #5800e4;
  background: #f9f0ff;
  z-index: 2;
}
.item-active::after {
  content: "";
  display: block;
  width: 2px;
  position: absolute;
  right: -2px;
  background: #4e30f5;
}
.msg-content {
  min-height: 600px;
  background-color: #fff;
}
.msg-item {
  box-sizing: border-box;
  display: flex;
  width: 800px;
  padding: 3% 2% 0 3%;
  margin-left: 25px;
  background: #fff;
  color: #000;
}
.msg-item-img {
  height: 75px;
  width: 75px;
}
.msg-item-img img {
  width: 75px;
  height: 75px;
  border-radius: 50%;
}
.msg-item-content {
  width: 90%;
  margin-left: 5%;
  text-align: left;
  padding-bottom: 40px;
  border-bottom: 1px solid #d9dbe1;
}
.msg-content-text {
  font-size: 20px;
  font-weight: 600;
}
.msg {
  font-weight: 400;
}
.msg-date {
  color: #969bab;
  margin-top: 5px;
}
</style>